<?php

namespace App\Handlers;

use App\Common\CommonFun;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redis;
use \GatewayWorker\Lib\Gateway;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Session;

// 心跳间隔10秒

class WorkermanHandler
{
    // businessWorker进程启动事件
    public static function onWorkerStart($businessWorker)
    {
    }
    //连接事件
    public static function onConnect($client_id)
    {
        // 向当前client_id发送数据
        Gateway::sendToClient($client_id, "Hello $client_id");
    }
    //进程退出事件
    public static function onWebSocketConnect($client_id, $data)
    {
    }
    //消息事件
    public static function onMessage($client_id, $message)
    {
//        var_dump($login_user['userId']);
//        exit;
//        if($login_user['sessionId'] !=Redis::get($login_user['userId'])){

              // return redirect()->guest( url('admin/login'));
          // }
//        }
        // 向所有人发送
        Gateway::sendToAll("$client_id said".$message.'_'.CommonFun::getSessionId());
    }
    // 连接断开事件
    public static function onClose($client_id)
    {
    }
}
